using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Domain.Model;
using NHibernate;
using NHibernate.Criterion;

namespace Core.Domain.Repositories
{
    public class #TABELA#Repository: IRepository<#TABELA#>
    {
        void IRepository<#TABELA#>.Save(#TABELA# entity)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(entity);
                    transaction.Commit();
                }
            }
        }

        void IRepository<#TABELA#>.Update(#TABELA# entity)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Update(entity);
                    transaction.Commit();
                }
            }
        }

        void IRepository<#TABELA#>.Delete(#TABELA# entity)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Delete(entity);
                    transaction.Commit();
                }
            }
        }
		
		#TABELA# IRepository<#TABELA#>.GetById(int #CHAVEPRIMARIA#)
		{
			using (ISession session = NHibernateHelper.OpenSession())
                return session.CreateCriteria<#TABELA#>().Add(Restrictions.Eq("#CHAVEPRIMARIA#", #CHAVEPRIMARIA#)).UniqueResult<#TABELA#>();
		
		}
        IList<#TABELA#> IRepository<#TABELA#>.GetAll()
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                ICriteria criteria = session.CreateCriteria(typeof(#TABELA#));
                return criteria.List<#TABELA#>();
            }
        }
    }
}
